import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { IotDeviceVO, IotDeviceForm, IotDeviceQuery } from '@/api/tearoom/iotDevice/types';

/**
 * 查询IoT设备列表
 * @param query
 * @returns {*}
 */

export const listIotDevice = (query?: IotDeviceQuery): AxiosPromise<IotDeviceVO[]> => {
  return request({
    url: '/tearoom/iotDevice/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询IoT设备详细
 * @param id
 */
export const getIotDevice = (id: string | number): AxiosPromise<IotDeviceVO> => {
  return request({
    url: '/tearoom/iotDevice/' + id,
    method: 'get'
  });
};

/**
 * 新增IoT设备
 * @param data
 */
export const addIotDevice = (data: IotDeviceForm) => {
  return request({
    url: '/tearoom/iotDevice',
    method: 'post',
    data: data
  });
};

/**
 * 修改IoT设备
 * @param data
 */
export const updateIotDevice = (data: IotDeviceForm) => {
  return request({
    url: '/tearoom/iotDevice',
    method: 'put',
    data: data
  });
};

/**
 * 修改IoT设备状态
 * @param data
 */
export const changeotDeviceStatus = (id: number | string, keyStatus: number) => {
  const data = {
    id,
    keyStatus
  };
  return request({
    url: '/tearoom/iotDevice/changeStatus',
    method: 'put',
    data: data
  });
};

/**
 * 删除IoT设备
 * @param id
 */
export const delIotDevice = (id: string | number | Array<string | number>) => {
  return request({
    url: '/tearoom/iotDevice/' + id,
    method: 'delete'
  });
};

// IoT 设备状态枚举
export enum DeviceStateEnum {
  INACTIVE = 2, // 未激活
  ONLINE = 1, // 在线
  OFFLINE = 0 // 离线
}

// IOT 产品设备类型枚举类 0: 直连设备, 1: 网关子设备, 2: 网关设备
export enum DeviceTypeEnum {
  DEVICE = 0, // 直连设备
  GATEWAY_SUB = 1, // 网关子设备
  GATEWAY = 2 // 网关设备
}
